import React from 'react';
import {
	RadioField,
	Button,
	Group,
	TextareaField,
	Toast,
	SelectField,
	CheckboxField,
} from 'saltui';
const {
	Count
} = TextareaField;
import PageController from 'pages/home';
import {
	urlPrefix,
	URLS,
	nodataIcon,
	dictMap
} from '../../../app/variables';
import DB from '../../../app/db';

import Util from 'components/common/util';
import Upload from 'components/upload';
let newBoardId="";
export default class PageHome extends React.Component {

	constructor(props) {
		
		super(props);
		
		this.postId = props.params.postId;
		this.boardId = props.params.boardId;

		this.state = {	
			id: this.postId,
			boardId: this.boardId,
			boradArray: [],
			
		}

			dd.biz.navigation.setTitle({
      		title: '选择版块',
		    onSuccess: function (result) {
		    },
     		 onFail: function () {
      		}
    		});
		
		

	}

	componentWillMount() {
		newBoardId="";
		// debugger;
		if (this.postId) {
			this.allBoard();
		}
	}

	componentDidMount() {

	}

	allBoard(){
		
		DB.ForumModuleAPI.postAllBoard({
			postId: this.postId,
			boardId: this.boardId
		}).then((content) => {
			Toast.hide();
			if (content && content.length > 0) {
				let array = [];
				content.map((item, index) => {
					let i = {
						checked:item.check,
						content: item.boardName,
						disable: false,
						value: item.boardId,
					}
					array.push(i);
				});
				
				this.setState({
					boradArray: array,
					
				})
			}
		}).catch((error) => {

		});
	}

	getCheckboxFieldProps() {
		return {
		  data: this.state.boradArray,
		  onChange(value, index, data) {
			console.log(value, index, data);
			newBoardId = value;
		  },
		  groupListArgument: {
			lineIndent: 15,
			itemIndent: 15,
		  },
		  groupListFlag: true,
		  className: 'ccc',
		  iconPosition: 'left',
		  required: true,
		  tip: '这里是提示信息',
		}
	}

	handleSubmit() {
		let postId = this.state.id;
		let oldBoardId = this.state.boardId;
		let boardId = newBoardId;
		DB.ForumModuleAPI.editPostBoard({
			postId:postId,
			oldBoardId:oldBoardId,
			boardId:boardId,
		}).then((content) => {
			Toast.hide();
			Toast.show({
				type: 'success',
				content: '移动成功'
			});
			history.go(-2);
			//window.salt.router.goBack();
		}).catch((error) => {
			if (typeof(error.errorMsg) == 'undefined') {
				Toast.show({
					type: 'error',
					content: '标签选择出错'
				});
			} else {
				Toast.show({
					type: 'error',
					content: error.errorMsg
				});
			}
		});
	}


	/**
	 * 取消提交表单
	 * @return {[type]}
	 */
	handleCancel() {
		history.go(-1);
	}
	
	

	render() {
	const radioFieldProps = this.getCheckboxFieldProps();
    return (
      <div className="checkbox-field-demo">

	    <div>
      <RadioField {...radioFieldProps} />
    </div>

         <div>
		<Button.Group className="page-add">					
		  <Button type="primary" display="inline"
		         onClick={this.handleSubmit.bind(this)}>确定</Button>
		  <Button type="secondary" display="inline"
		         onClick={this.handleCancel.bind(this)}>取消</Button>
		</Button.Group>
	</div>	
      </div>

     
    );
  }
}